# -*- coding:utf-8 -*-

import binascii
import time
from module.ksw import Ksw
from module.store import Store

from multiprocessing.dummy import Pool as ThreadPool #多线程
def main():

    # 初始化数据库
    Store.init()
    start_time = time.time()
    ls = list(range(1,999999))
    pool = ThreadPool()
    pool.map(handle, ls)
    pool.close()
    pool.join()
    print('%d second'% (time.time()-start_time))
def handle(ls):
    n = ls*10000
    form = str(n).zfill(10)
    url = "http://hs.bianmachaxun.com/query/detail.php?word=" + form
    info = Ksw.getcontent(url)
    if (info == "no"):
        print("hs编码：%s-----无数据" % form)
    else :
        Store.save([(info["code"],info["cn_describe"],info["en_describe"],info["elements"],info["example"])])
        print("hs编码：%s-----抓取完毕,储存成功" % form)
if __name__ == "__main__":
    main()
